package com.emep.changzhi.analyse.http.datamonitor.minute;

import com.datastax.driver.core.PagingState;
import com.emep.changzhi.analyse.entity.datamonitor.minute.DataMinuteIndustrialGas;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.datamonitor.minute.DataMinuteIndustrialGasService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangj
 * @version V1.0
 * @Description: DOTO
 * @date 2018/2/27  17:44
 */
@RequestMapping("industrialgasminute")
@RestController
@Api(value="工业废气监测_分钟数据controller",tags={"工业废气监测_分钟数据"})
public class DataMinuteIndustrialGasController {

    @Autowired
    private DataMinuteIndustrialGasService dataMinuteIndustrialGasService;

    /**
     * 新增工业废气监测_分钟数据
     * @param payload
     * @return
     */
    @ApiOperation(value="新增工业废气监测_分钟数据", notes="新增工业废气监测_分钟数据")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改时传的id", required = false, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "areaCode", value = "行政区划", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "mn", value = "设备mn号", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "packetDate", value = "报文时间", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "SO2_value", value = "污染物简称_检测值", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "SO2_status", value = "污染物简称_状态", required = true, dataType = "String",paramType="query")
    })
    @PostMapping(value = "add")
    public ResultBean<DataMinuteIndustrialGas> add(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "areaCode","mn","packetDate","SO2_value","SO2_status");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return result.boolAdd(dataMinuteIndustrialGasService.save(payload)) ;
        }
        return  result;
    }

//    @ApiOperation(value="分页查询", notes="分页无参数查询")
//    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
//            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
//            @ApiResponse(code = 303, message = "权限不足") })
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pageSize", value = "数量", required = true, dataType = "String",paramType="query"),
//            @ApiImplicitParam(name = "flag", value = "分页", required = true, dataType = "String",paramType="query")
//    })
//    @GetMapping(value = "findNoQuery")
//    public String findNoQuery(@RequestParam Map<String, Object> payload){
//        Map<String , Object> result = new HashMap<String , Object>();
//        PagingState pagingState = null;
//        if(Integer.parseInt(payload.get("flag").toString()) == 0){
//            result = dataMinuteIndustrialGasService.findNoQuery(Integer.parseInt(payload.get("pageSize").toString()),null);
//            pagingState = (PagingState) result.get("pagingState");
//        }else{
//            result = dataMinuteIndustrialGasService.findNoQuery(Integer.parseInt(payload.get("pageSize").toString()),pagingState);
//            pagingState = (PagingState) result.get("pagingState");
//        }
//
//        return pagingState.toString();
//
////        return new ResponseEntity<List<DataMinuteIndustrialGas>>(dataMinuteIndustrialGasService.findNoQuery(Integer.parseInt(payload.get("pageIndex").toString()),Integer.parseInt(payload.get("pageSize").toString())), HttpStatus.OK);
//    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="首页", notes="首页")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "home")
    public List<DataMinuteIndustrialGas> findDataMinuteIndustrialGasByHome(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            return dataMinuteIndustrialGasService.findDataMinuteIndustrialGasByHome(Integer.parseInt(payload.get("pageSize").toString()));
        }
        return  null;
    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 11:49
     * @version V1.0
     */
    @ApiOperation(value="翻页查询", notes="翻页查询")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "查询起始id", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "pageSize", value = "查询数量", required = true, dataType = "Integer",paramType="query")
    })
    @GetMapping(value = "flip")
    public List<DataMinuteIndustrialGas> findDataMinuteIndustrialGasByFlip(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "id","pageSize");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            return dataMinuteIndustrialGasService.findDataMinuteIndustrialGasByFlip(payload.get("id").toString() , Integer.parseInt(payload.get("pageSize").toString()));
        }
        return null;
    }
}
